package com.zhku.zeng.wxdev.controller.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HappyOlTopicConveterUtil {

    ArrayList<ArrayList<String>> data;
    ArrayList<Map<String,String>> targetData;

    public HappyOlTopicConveterUtil(ArrayList<ArrayList<String>> data) {
        this.data = data;

    }

    public void getTarget() throws JsonProcessingException {
        targetData = new ArrayList<>();
        ObjectMapper mapper = new ObjectMapper();

        for (ArrayList<String> line : data) {

            String correctAnswer = line.get(6);
            List<AnswerUtil> tempAnswer = new ArrayList<>();


            for (int i = 0; i < 4; i++) {
                String answer = line.get(2 + i);
                AnswerUtil answerUtil = new AnswerUtil();
                answerUtil.setNumber((i+1)+"");
                answerUtil.setContent(answer);
                Character c = Character.valueOf((char) (65 + i));
                answerUtil.setCorrectOption(correctAnswer.contains(c.toString()));
                tempAnswer.add(answerUtil);
            }
            String s1 = mapper.writeValueAsString(tempAnswer);
            Map m = new HashMap();
            m.put("options", s1);
            m.put("question", line.get(1));
            targetData.add(m);
        }

    }

    public ArrayList<Map<String,String>> getTargetData() {
        return targetData;
    }
}
